package com.aegean.CommercialHotelBookSystem.shop.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.model.Hotel;
import com.aegean.CommercialHotelBookSystem.model.Room;

/**
 * Servlet implementation class ShopHotel_ClickTide
 */
public class ShopHotel_ClickTide extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int page = Integer.parseInt(request.getParameter("page")) - 1;
		HttpSession session = request.getSession();
		List<Hotel> roomclick = (List<Hotel>) session
				.getAttribute("ShopHotelClick_Hotels");
		List<Hotel> room2click = new ArrayList<Hotel>();
		int pagecount = (roomclick.size() + 8 - 1) / 8;
		request.setAttribute("Hotel_Clickhotel_page", pagecount);
		for (int i = page * 8; i < page * 8 + 8; i++) {
			Hotel one = roomclick.get(i);
			room2click.add(one);
			if (i == roomclick.size() - 1) {
				break;
			}
		}
		session.setAttribute("ShopHotelClick_moreHotels", room2click);
		request.getRequestDispatcher("Hotel_Clickhotel.jsp").forward(request,
				response);
	}
}
